<?php
class Product extends FrontAction{
	function index($pagenow,$pagesize){
		
		$lang = getlang();
		$db = $this->getDB();		
		
		
		require loadinc('front_pagesplit');
		
		$rownums = $db->get_assoc("select count(*) as rownums from product where lang = '".$this->lang."' ");
		$rownums = $rownums['rownums'];
		
		$pagesplit = new PageSplit();
		$pagecount = $pagesplit->getPageCount($pagesize,$rownums);
		$start = $pagesplit->getStart($pagesize,$pagenow);
		//echo "select distinct(proc.id),proc.pname,proc.pdesc,proc.createtime,pimg.imgurl from product proc left join product_images pimg on proc.id = pimg.pid  where proc.lang = '".$this->lang."' group by proc.id limit ".$start.",".$pagesize;
		$products = $db->query_assoc("select proc.id,proc.pname,proc.pdesc,proc.createtime from product proc  where proc.lang = '".$this->lang."' limit ".$start.",".$pagesize);
		$links = "/index.php/product/index";
		$pagebar = $pagesplit->getPageBar($links,$pagenow,$pagesize,$pagecount,$this->lang);

		$prodlist = array();
		foreach ($products as $pr){
			$img = $db->get_assoc("select imgurl from product_images where pid = ".$pr['id']);
			$pr['imgurl']=$img['imgurl'];
			$prodlist[] = $pr;
		}
		
		$topproducts = $db->query_assoc("select * from product where lang = '".$this->lang."'  limit 0,20");
		$this->data['topproducts'] = $topproducts; 
		
		$this->data['pagebar'] = $pagebar;
		$this->data['products']=$prodlist;
		
		template('product',$this->data);
	}
	
	function show($pid){
		$db = $this->getDB();	
		
		$product = $db->get_assoc("select * from product where id = $pid");
		$this->data['product'] = $product;
		
		$topproducts = $db->query_assoc("select * from product where lang = '".$this->lang."' limit 0,20");
		$this->data['topproducts'] = $topproducts; 
		
		template('product_show',$this->data);
	}
	
}